#include "SQLSubPartitionBy.h"
#include "SQLObjectImpl.h"
#include "SQLExpr.h"
#include "SQLSubPartition.h"
#include "statement/SQLAssignItem.h"
#include "expr/SQLIntegerExpr.h"

SQLSubPartitionBy::SQLSubPartitionBy()
{
  options = std::make_shared<std::list<SQLAssignItem_ptr>>();
  subPartitionTemplate = std::make_shared<std::list<SQLSubPartition_ptr>>();
}

SQLExpr_ptr SQLSubPartitionBy::getSubPartitionsCount()
{
  return subPartitionsCount;
}

void SQLSubPartitionBy::setSubPartitionsCount(SQLExpr_ptr x)
{
  if (x != nullptr)
  {
    x->setParent(SharedObject(SQLSubPartitionBy));
  }

  this->subPartitionsCount = x;
}

BOOL_ptr SQLSubPartitionBy::isLinear()
{
  return linear;
}

void SQLSubPartitionBy::setLinear(BOOL_ptr linear)
{
  this->linear = linear;
}

SQLAssignItem_list_ptr SQLSubPartitionBy::getOptions()
{
  return options;
}

SQLSubPartition_list_ptr SQLSubPartitionBy::getSubPartitionTemplate()
{
  return subPartitionTemplate;
}

void SQLSubPartitionBy::cloneTo(SQLSubPartitionBy_ptr x)
{
  if (subPartitionsCount != nullptr)
  {
    x->setSubPartitionsCount(std::dynamic_pointer_cast<SQLExpr>(subPartitionsCount->clone()));
  }
  x->linear = linear;
  for (SQLAssignItem_ptr option : *options)
  {
    SQLAssignItem_ptr option2 = std::dynamic_pointer_cast<SQLAssignItem>(option->clone());
    option2->setParent(SharedObject(SQLSubPartitionBy));
    x->options->push_back(option2);
  }

  for (SQLSubPartition_ptr p : *subPartitionTemplate)
  {
    SQLSubPartition_ptr p2 = std::dynamic_pointer_cast<SQLSubPartition>(p->clone());
    p2->setParent(SharedObject(SQLSubPartitionBy));
    x->subPartitionTemplate->push_back(p2);
  }

  x->lifecycle = lifecycle;
}

SQLIntegerExpr *SQLSubPartitionBy::getLifecycle()
{
  return lifecycle;
}

void SQLSubPartitionBy::setLifecycle(SQLIntegerExpr *lifecycle)
{
  this->lifecycle = lifecycle;
}

BOOL_ptr SQLSubPartitionBy::isPartitionByColumn(long columnNameHashCode64)
{
  return BOOL::FALSE;
}
